﻿package mortal.game.scene3D.layer3D.utils
{
    import com.gengine.debug.*;
    import frEngine.pools.*;
    import mortal.game.*;
    import mortal.game.scene3D.layer3D.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.map3D.sceneInfo.*;
    import mortal.game.scene3D.player.item.*;

    public class StatueUtil extends EntityLayerUtil
    {
        private var _statueMap:StatueDictionary;

        public function StatueUtil(param1:PlayerLayer)
        {
            this._statueMap = new StatueDictionary();
            super(param1);
            return;
        }// end function

        public function getStatue(param1:int) : StatuePlayer
        {
            return this._statueMap.getStatue(param1);
        }// end function

        private function addStatuePlayer(param1:CrossMainCityStatueInfo) : StatuePlayer
        {
            var _loc_2:* = this._statueMap.getStatue(param1.id) as StatuePlayer;
            if (_loc_2 == null)
            {
                _loc_2 = FrObjectPool.getObject(StatuePlayer, this) as StatuePlayer;
                this._statueMap.addStatue(param1.id, _loc_2);
            }
            _loc_2.updateStatue(param1);
            Log.debug("增加雕像:" + [param1.x, param1.y]);
            layer.addChild(_loc_2);
            return _loc_2;
        }// end function

        public function removeStatuePlayer(param1:int) : void
        {
            var _loc_2:* = this._statueMap.removeStatue(param1);
            if (_loc_2)
            {
                _loc_2.parent = null;
                _loc_2.dispose();
            }
            return;
        }// end function

        override public function removeAll() : void
        {
            this._statueMap.removeAll();
            return;
        }// end function

        override public function updateEntity() : void
        {
            var _loc_2:CrossMainCityStatueInfo = null;
            var _loc_3:StatuePlayer = null;
            if (!Game.sceneInfo)
            {
                return;
            }
            var _loc_1:* = Game.sceneInfo.crossMainCityStatueInfos;
            if (!_loc_1 || _loc_1.length < 1)
            {
                return;
            }
            for each (_loc_2 in _loc_1)
            {
                
                if (SceneRange.isInEntityRange(_loc_2.x, _loc_2.y, 300, 500))
                {
                    _loc_3 = this.getStatue(_loc_2.id);
                    if (_loc_3 == null)
                    {
                        _loc_3 = this.addStatuePlayer(_loc_2);
                    }
                    else if (_loc_3.parent == null)
                    {
                        layer.addChild(_loc_3);
                    }
                    continue;
                }
                this.removeStatuePlayer(_loc_2.id);
            }
            return;
        }// end function

    }
}
